package ai.restosuite.infrastructure.operation.work;

import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class WorkController {

    @Autowired
    RuntimeService runtimeService;

    @Autowired
    TaskService taskService;
    @GetMapping("/startProcessInstance")
    public String startProcessInstance(@RequestParam("processDefineKey")String processDefineKey,
                                       @RequestParam("startUser")String startUser) {
        /**
         * 1.先判断用户是否在系统中，不在就返回用户不存在
         */

        /**
         * 2.封装参数
         */
        Map<String, Object> map = new HashMap<>();
        map.put("startUser", StringUtils.isBlank(startUser)?"admiin":startUser);
        map.put("servicie","test服务");
        map.put("name","BPMS");
       //发起流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefineKey, map);
        return processInstance.getProcessInstanceId();
    }
}
